﻿<!DOCTYPE HTML>
<html>
<head>
    <title>用户列表</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <script src="/static/js/common/common.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        body {
            margin:0;
            padding:0;
            border:0;
            width:100%;
            height:100%;
            overflow:hidden;
        }
    </style>
</head>
<body>
<div class="mini-splitter" style="width:100%;height:100%;" borderStyle="border:8px;">
    <!-- 左边树 -->
    <div size="300" showCollapseButton="true">
        <div class="mini-fit" style="margin-top: 10px;margin-left: 10px">
            <!--Tree -->
            <ul id="tree1" class="mini-tree" url="/basic/departments/loadTree"
                showTreeIcon="true"
                ShowExpandButtons="true"
                resultAsTree="false" expandOnLoad='false'
                textField="name" idField="id" parentField="pid"
                contextMenu="#treeMenu"
                onbeforeload="onBeforeTreeLoad"
                expandOnNodeClick="false"
                expandOnLoad="true"
            >
            </ul>
        </div>
    </div>
    <div showCollapseButton="false" style="overflow: auto;padding:0px;" borderStyle="border:solid 1px #aaa;">
        <div class="role-search">
            <div class="mini-toolbar"
                 style="padding:2px;border-top:0;border-left:0;border-right:0;background-color: #9cdbf7;">
                <table>
                    <tr>
                        <td style="width: 100%;">
                            <a class="mini-button" iconCls="fa fa-plus" onclick="addUser()" plain="true">新增</a>
                        </td>
                        <td style="white-space: nowrap;text-align:right;">
                            <input class="mini-textbox" id="usernameKey" class="mini-textbox" emptyText="用户名"
                                   onenter="onKeyEnter" />
                            <a class="mini-button" plain="true" iconCls="icon-search" plain="true"
                               onclick="searchUser()">查询</a>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <!--撑满页面-->
        <div class="mini-fit">
            <div id="datagrid1" class="mini-datagrid" style="width: 100%; height: 97%;display:none" ajaxType="get"
                 sizeList="[20,50,100]" pageSize="50" allowResize="true" url="/basic/user/getUserList"
                 idField="id">
                <input id="orgid" name="orgid" class="mini-hidden" style="width: 100%;" readonly />
                <input name="departid" class="mini-hidden" style="width: 100%;" readonly />
                <input name="roleIds" class="mini-hidden" style="width: 100%;" readonly />
                <input name="roleid" class="mini-hidden" style="width: 100%;" readonly />
                <input name="roleGroupIds" class="mini-hidden" style="width: 100%;" readonly />
                <div property="columns">
                    <div name="account" width="30" field="account" align="center" headerAlign="center"
                         allowSort="false">账号
                    </div>
                    <div name="username" width="30" field="username" align="center" headerAlign="center"
                         allowSort="false">用户名
                    </div>
                    <div name="departName" field="departName" width="40" align="center" headerAlign="center"
                         allowSort="false">部门
                    </div>
                    <div name="roleName" field="roleName" width="30" align="center" headerAlign="center"
                         allowSort="false">角色
                    </div>
                    <div name="action" headerAlign="center" width="40" align="center" renderer="onActionRenderer"
                         cellStyle="padding:0;"
                         allowSort="false" multiSelect="false">操作
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    mini.parse();
    var tree = mini.get("tree1");
    var grid = mini.get("datagrid1");
    var mima = '${mima!''}';

    function onBeforeTreeLoad(e) {
        var tree = e.sender;    //树控件
        var node = e.node;      //当前节点
        var params = e.params;  //参数对象
    }

    //渲染列中按钮
    function onActionRenderer(e) {
        var s = '';
        s += '&nbsp;<a class="mini-button mini-button-danger"   onclick="resetPwd()" >重置密码&nbsp;</a>&nbsp';
        s += '&nbsp;<a class="mini-button mini-button-primary"   onclick="edituser()" >编辑&nbsp;</a>&nbsp';
        s += '&nbsp;<a class="mini-button mini-button-danger"   onclick="deluser();" >删除&nbsp;</a>&nbsp';
        return s;
    }

    tree.on("nodeSelect", function (e) {
        document.getElementById("datagrid1").style.display = "block";
        var row = tree.getSelectedNode();
        grid.load({pid: row.pid, id: row.id, orgid: row.orgid});
    });

    //新增用户
    function addUser() {
        var row = tree.getSelectedNode();
        if (row == null || row == "" || row == undefined) {
            mini.alert("请选择一个机构进行新增操作");
        } else {
            var root = tree.getParentNode(row);
            var root1 = tree.getLevel(root);
            row.action = "add";
            showUserWindow(row, 1);
        }
    }

    //修改用户
    function edituser() {
        var row = grid.getSelected();
        if (row) {
            showUserWindow(row, 2);
        } else {
            mini.alert("请至少选择一条数据！");
        }
    }

    //重置密码
    function resetPwd() {
        var row = grid.getSelected();
        if (row) {
            mini.confirm("密码将重置为默认密码" + mima + ",重置后请及时登录账号进行修改！", "确定？",
                function (action) {
                    if (action == "ok") {
                        $.ajax({
                            url: "/basic/user/resetPwd?account=" + row.account,
                            type: "post",
                            cache: false,
                            success: function (result) {
                                if (result.code == 1) {
                                    mini.alert("重置成功！");
                                } else {
                                    mini.alert("重置失败，请重试！");
                                }
                            }
                        });
                    }
                });
        } else {
            mini.alert("请至少选择一条数据！");
        }
    }

    function showUserWindow(row, flag) {
        commonEdit("/basic/user/edit?flag=" + flag, "用户信息", row, 700, 375, true, false, true, callback);

        function callback() {
            grid.reload();
        }
    }

    function deluser() {
        var row = grid.getSelected();
        if (row) {
            commonRemove("/basic/user/" + row.account, row, {_method: "delete"}, callback);

            function callback() {
                grid.reload();
            }
        } else {
            mini.alert("请至少选中一条记录");
        }
    }

    //查询
    function onKeyEnter(e) {
        searchUser();
    }

    function searchUser() {
        var usernameKey = mini.get("usernameKey").getValue();
        var row = tree.getSelectedNode();
        if (typeof row == 'undefined') {
            mini.alert("请先选择用户进行查询！");
            return;
        }
        grid.load({usernameKey: usernameKey, pid: row.pid, id: row.id, orgid: row.orgid});
    }
</script>
</body>
</html>